#include "linux/module.h"
#include "linux/init.h"

#include "linux/platform_device.h"

#define MEM_START_ADDR 0xFDD60000
#define MEM_END_ADDR 0xFDD60004
#define IRQ_NUMBER 101

struct resource my_resources[] = {
    {
        .start = MEM_START_ADDR,
        .end = MEM_END_ADDR,
        .flags = IORESOURCE_MEM,
    },
    {
        .start = IRQ_NUMBER,
        .end = IRQ_NUMBER,
        .flags = IORESOURCE_IRQ,
    },
};

void my_platform_device_release(struct device *dev)
{
    printk("资源已释放\n");
}

struct platform_device platform_device_test = {
    .name = "LYH_platform_device",
    .id = 1,
    .num_resources = ARRAY_SIZE(my_resources),
    .resource = my_resources,
    .dev.release = my_platform_device_release,
};

int __init my_platform_device_init(void)
{
    int ret;
    printk("平台设备加载\n");
    ret = platform_device_register(&platform_device_test);
    if (ret < 0)
    {
        printk("平台设备注册失败\n");
        return -1;
    }
    printk("平台设备注册成功\n");
    return 0;
}
void __exit my_platform_device_exit(void)
{
    platform_device_unregister(&platform_device_test);
    printk("平台设备卸载\n");
}

module_init(my_platform_device_init);
module_exit(my_platform_device_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("LYH");